package com.ruoyi.system.outto.goods.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttrTemplateMapper;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.gameAttr.service.IGameAttributeService;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.interAttr.mapper.InterAttrMapper;
import com.ruoyi.system.model.domain.ArtRec;
import com.ruoyi.system.model.domain.GameAttribute;
import com.ruoyi.system.model.domain.GoodsInfoImg;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.core.MapUntils;
import com.ruoyi.system.outto.core.constant.GameTypeConstant;
import com.ruoyi.system.outto.goods.NEWLXYAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/8/16 22:58
 */
@Slf4j
@Service
public class NEWLYXApiImpl implements NEWLXYAPI {

    @Resource
    private IGameAttributeService gameAttributeService;
    @Resource
    InterAttrMapper interAttrMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private ArtRecMapper artRecMapper;
    @Resource
    private GameAttrTemplateMapper gameAttrTemplateMapper;

    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner sa) {
        Map<String, Object> resultMap = new HashMap<>();
        String url = sa.getThreeOther();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, sa, "AddGame");
        String requestp = JSONObject.toJSONString(params);
        log.info("乐逍遥添加接口请求参数={}", requestp);
        String type = goodsInfoAndAttrValueDto.getGameName();
        String result = null;
        if (type.equals(GameTypeConstant.WZRY)) {
            if(sa.getSaleKey().contains("28c8edde3d61a0411511d3b1866f0636")){
                result = HttpUtils.doPostForm("http://lexiaoyao.sycwy.cn/api/partner/wz.php", params, null);
            }else {
                if(sa.getOther().equals("zhumengyou")) {//逐梦游的国服
                    result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/guofu.php", params, null);
                }else {
                    result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/wz.php", params, null);
                }
            }
        } else if (type.equals(GameTypeConstant.HPJY)) {
            result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/heping.php", params, null);
        } else if (type.equals(GameTypeConstant.YS)) {
            result = HttpUtils.doPostForm("http://ys.sycwy.cn/api/partner/ys.php", params, null);
        } else if (type.equals(GameTypeConstant.WZGF)) {
            result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/guofu.php", params, null);
        }
        log.info("乐逍遥添加接口返回参数={}", MapUntils.unicodeToString(result));

        JSONObject resultJson = JSONObject.parseObject(result);
        if (!"200".equals(resultJson.getString("status"))) {
            resultMap.put("code", 500);
        } else {
            resultMap.put("code", 200);
            resultMap.put("outId", goodsInfoAndAttrValueDto.getId());
        }
        resultMap.put("req", requestp);
        resultMap.put("res", MapUntils.unicodeToString(result));
        resultMap.put("msg", resultJson.toJSONString());

        return AjaxResult.success(resultMap);
    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner sa) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, sa, "EditGame");
        String type = goodsInfoAndAttrValueDto.getGameName();
        String requestp = JSONObject.toJSONString(params);
        log.info("乐逍遥编辑接口请求参数={}", requestp);
        String result = null;
        if (type.equals(GameTypeConstant.WZRY)) {
            if(sa.getSaleKey().contains("28c8edde3d61a0411511d3b1866f0636")){
                result = HttpUtils.doPostForm("http://lexiaoyao.sycwy.cn/api/partner/wz.php", params, null);
            }else {
                result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/wz.php", params, null);
            }
        } else if (type.equals(GameTypeConstant.HPJY)) {
            result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/heping.php", params, null);
        } else if (type.equals(GameTypeConstant.YS)) {
            result = HttpUtils.doPostForm("http://ys.sycwy.cn/api/partner/ys.php", params, null);
        } else if (type.equals(GameTypeConstant.WZGF)) {
            result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/guofu.php", params, null);
        }
        log.info("乐逍遥编辑接口返回参数={}", MapUntils.unicodeToString(result));

        JSONObject resultJson = JSONObject.parseObject(result);
        if (!"200".equals(resultJson.getString("status"))) {
            resultMap.put("code", 500);
        } else {
            resultMap.put("code", 200);
        }
        resultMap.put("req", requestp);
        resultMap.put("res", MapUntils.unicodeToString(result));
        resultMap.put("msg", resultJson.toJSONString());
        return AjaxResult.success(resultMap);

    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner sa) {
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(sa.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        goodsInfoAndAttrValueDto.setOutId(artRecs.get(0).getOutid());
        Map<String, Object> resultMap = new HashMap<>();
        String url = sa.getThreeOther();
        Map<String, Object> params = new TreeMap<>();
        params.put("type", "DelGame");
        params.put("username", sa.getOther());
        String requestp = JSONObject.toJSONString(params);
        String result = null;
        String type = goodsInfoAndAttrValueDto.getGameName();
        String[] strings = sa.getSaleKey().split(",");
        if (type.equals(GameTypeConstant.WZRY)) {
            params.put("tianxai_id", goodsInfoAndAttrValueDto.getOutId());
            String cover = MapUntils.getCover(params);
            if(sa.getSaleKey().contains("28c8edde3d61a0411511d3b1866f0636")){
                cover = cover + "key=" + "28c8edde3d61a0411511d3b1866f0636";
            }else {
                cover = cover + "key=" + "614f757da7117ef6e631f6780cbcb0ea";
            }
            log.info(cover);
            String sign = DigestUtils.md5Hex(cover).toUpperCase();
            params.put("sign", sign);
            log.info("乐逍遥删除接口请求参数={}", params);
            if(sa.getSaleKey().contains("28c8edde3d61a0411511d3b1866f0636")){
                result = HttpUtils.doPostForm("http://lexiaoyao.sycwy.cn/api/partner/wz.php", params, null);
            }else {
                result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/wz.php", params, null);
            }
        } else if (type.equals(GameTypeConstant.HPJY)) {
            params.put("game_id", goodsInfoAndAttrValueDto.getOutId());
            String cover = MapUntils.getCover(params);
            cover = cover + "key=ebb8dd14ff84552eab6c4bbccf5c9d32";
            log.info(cover);
            String sign = DigestUtils.md5Hex(cover).toUpperCase();
            params.put("sign", sign);
            log.info("乐逍遥删除接口请求参数={}", params);
            result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/heping.php", params, null);
        } else if (type.equals(GameTypeConstant.YS)) {
            params.put("product_id", goodsInfoAndAttrValueDto.getOutId());
            String cover = MapUntils.getCover(params);
            cover = cover + "key=28c8edde3d61a0411511d3b1866f0636";
            log.info(cover);
            String sign = DigestUtils.md5Hex(cover).toUpperCase();
            params.put("sign", sign);
            log.info("乐逍遥删除接口请求参数={}", params);
            result = HttpUtils.doPostForm("http://ys.sycwy.cn/api/partner/ys.php", params, null);
        } else if (type.equals(GameTypeConstant.WZGF)) {
            params.put("gfbianhao", goodsInfoAndAttrValueDto.getOutId());
            String cover = MapUntils.getCover(params);
            cover = cover + "key=614f757da7sek9f6e631f6780cbcb0ea";
            log.info(cover);
            String sign = DigestUtils.md5Hex(cover).toUpperCase();
            params.put("sign", sign);
            log.info("乐逍遥删除接口请求参数={}", params);
            result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/guofu.php", params, null);
        }
        log.info("乐逍遥删除接口返回参数={}", MapUntils.unicodeToString(result));
        JSONObject resultJson = JSONObject.parseObject(result);
        if (!"200".equals(resultJson.getString("status"))) {
            resultMap.put("code", 500);
        } else {
            resultMap.put("code", 200);
        }

        resultMap.put("req", requestp);
        resultMap.put("res", MapUntils.unicodeToString(result));
        resultMap.put("msg", resultJson.toJSONString());
        return AjaxResult.success(resultMap);
    }

    private Map<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner sa, String type) {
        GameAttribute gameAttribute = null;
        if (goodsInfoAndAttrValueDto.getGameName().contains("王者荣耀") || goodsInfoAndAttrValueDto.getGameName().contains("王者国服")) {
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("和平精英")) {
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("原神")) {
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("穿越火线")) {
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("光遇")) {//=================================未配置游戏属性
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("英雄联盟")) {
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("火影忍者")) {//=================================未配置游戏属性
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("枪战王者")) {
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
        } else {
            throw new GlobalException("当前游戏暂不支持");
        }
        Map<String, Object> params = new TreeMap<>();
        String gameType = goodsInfoAndAttrValueDto.getGameName();
        String pfIds = "";
        if (goodsInfoAndAttrValueDto.getGameName().contains("王者荣耀") || goodsInfoAndAttrValueDto.getGameName().contains("王者国服")) {
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF9());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF10());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF11());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF12());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF15());
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("和平精英")) {
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF1());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF2());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF3());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF4());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF5());
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("原神")) {
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF11());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF17());
        }
        String s = "";
        if (goodsInfoAndAttrValueDto.getGameName().equals("原神")) {
            s = regionalCover(sa,goodsInfoAndAttrValueDto.getGameName(), goodsInfoAndAttrValueDto.getCarrierName());
        } else {
            s = regionalCover(sa,goodsInfoAndAttrValueDto.getGameName(), goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName());
        }
        if (Objects.isNull(s)) {
            throw new GlobalException("区服匹配失败，当前游戏:" + gameType + "，区服" + goodsInfoAndAttrValueDto.getServerName() + goodsInfoAndAttrValueDto.getCarrierName());
        }
        params.put("type", type);
        params.put("catid", s);
        params.put("title", goodsInfoAndAttrValueDto.getDes().replace("+", "").trim());
        String titleImg = goodsInfoAndAttrValueDto.getTitleImg();
        params.put("thumb", StringUtils.isEmpty(titleImg) ? "https://game.ikbh.top/logo/no_img.jpg" : titleImg);
        params.put("username", sa.getOther());
        List<GameAttribute> gameAttributesss = getGameAttributs(pfIds);
        BigDecimal bigDecimal = goodsInfoAndAttrValueDto.getPrice();
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(sa.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        String account_id = CollectionUtils.isNotEmpty(artRecs) ? artRecs.get(0).getOutid() : goodsInfoAndAttrValueDto.getId().toString();
        if (gameType.equals(GameTypeConstant.WZRY)) {
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF3())) {
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
                if (!Objects.isNull(gameAttribute)) {
                    if (!gameAttribute1.getFieldName().contains("王者")) {
                        params.put("ztdw", gameAttribute1.getFieldName());
                    } else {
                        params.put("ztdw", "王者");
                    }
                } else {
                    params.put("ztdw", "王者");
                }
            } else {
                params.put("ztdw", "青铜");
            }
            params.put("camp", goodsInfoAndAttrValueDto.getF17() == null || goodsInfoAndAttrValueDto.getF17().equals("") ? "0" : goodsInfoAndAttrValueDto.getF17());
            params.put("ztpf", goodsInfoAndAttrValueDto.getF8() == null || goodsInfoAndAttrValueDto.getF8().equals("") ? "0" : goodsInfoAndAttrValueDto.getF8());
            params.put("ztmw", goodsInfoAndAttrValueDto.getF13() == null || goodsInfoAndAttrValueDto.getF13().equals("") ? "0" : goodsInfoAndAttrValueDto.getF13());
            params.put("daqu", goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName());
            params.put("dengji", "30");
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF2())) {
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF2()));
                String[] guizus = "1=>V1、2=>V2、3=>V3、4=>V4、5=>V5、6=>V6、7=>V7、8=>V8、9=>V9、10=>V10".split("、");
                String gz = "";
                for (String string : guizus) {
                    String[] strings = string.split("=>");
                    if (gameAttribute1.getFieldName().equals(strings[1])) {
                        gz = strings[0];
                        break;
                    }
                }
                if (StringUtils.isEmpty(gz)) {
                    gz = "1";
                }
                params.put("gzdj", gz);
            } else {
                params.put("gzdj", "1");
            }
            params.put("tianxai_id", account_id);
            params.put("ztprice", String.valueOf(Math.round(bigDecimal.doubleValue())));

            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF16())) {
                if (gameAttribute.getFieldName().equals("可二次实名")) {
                    params.put("shiming", 1102);
                } else if (gameAttribute.getFieldName().equals("不可二次实名")) {
                    params.put("shiming", 1103);
                } else if (gameAttribute.getFieldName().equals("包人脸")) {
                    params.put("shiming", 1101);
                } else {
                    params.put("shiming", 1110);
                }
            }else {
                params.put("shiming", 1103);
            }
        } else if (gameType.equals(GameTypeConstant.HPJY)) {
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF16()) && !"0".equals(goodsInfoAndAttrValueDto.getF16()) && Integer.parseInt(goodsInfoAndAttrValueDto.getF16()) < 26) {
                params.put("duanweip", goodsInfoAndAttrValueDto.getF16());
            } else {
                params.put("duanweip", "1");
            }
            params.put("skinnum", goodsInfoAndAttrValueDto.getF9() == null || goodsInfoAndAttrValueDto.getF9().equals("") ? 10 : Integer.parseInt(goodsInfoAndAttrValueDto.getF9()));
            params.put("hdengji", 30);
            params.put("ztpricep", String.valueOf(Math.round(bigDecimal.doubleValue())));
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF10())) {
                if (gameAttribute.getFieldName().equals("可二次实名")) {
                    params.put("shiming", 2);
                } else if (gameAttribute.getFieldName().equals("不可二次实名")) {
                    params.put("shiming", 1);
                } else if (gameAttribute.getFieldName().equals("包人脸")) {
                    params.put("shiming", 4);
                } else {
                    params.put("shiming", 3);
                }
            }
            params.put("qiangxiep", goodsInfoAndAttrValueDto.getF9() == null || goodsInfoAndAttrValueDto.getF9().equals("") ? 20 : Integer.parseInt(goodsInfoAndAttrValueDto.getF9()));
            params.put("game_id", account_id);
        } else if (gameType.equals(GameTypeConstant.YS)) {
            String email = "";
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF2())) {
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF2()));
                if (gameAttribute1.getFieldName().contains("已实名")) {
                    email = "1";
                } else if (gameAttribute1.getFieldName().contains("未实名")) {
                    email = "2";
                } else if (gameAttribute1.getFieldName().equals("未绑定邮箱")) {
                    email = "3";
                } else if (gameAttribute1.getFieldName().equals("邮箱已注销")||gameAttribute1.getFieldName().equals("不送邮箱/死邮")||gameAttribute1.getFieldName().contains("Q")) {
                    email = "4";
                } else {
                    email = "1";
                }
            }
            params.put("email", email);
            params.put("price", String.valueOf(Math.round(bigDecimal.doubleValue())));
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF11())) {
                params.put("num", goodsInfoAndAttrValueDto.getF11().split(",").length);
            } else {
                params.put("num", 0);
            }
            params.put("yuanshi", 0);
            params.put("dengji", goodsInfoAndAttrValueDto.getF7() == null ? 0 : goodsInfoAndAttrValueDto.getF7());
            params.put("product_id", account_id);
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF11())) {
                String wuxing = "";
                List<GameAttribute> gameAttributeList = getGameAttributs(goodsInfoAndAttrValueDto.getF11());
                JSONArray jsonArray = JSONArray.parseArray(getWuxing());
                for (GameAttribute gameAttribute1 : gameAttributeList) {
                    for (Object o : jsonArray) {
                        if (gameAttribute1.getFieldName().contains(JSONObject.parseObject(o.toString()).getString("name"))) {
                            wuxing += "," + JSONObject.parseObject(o.toString()).getString("id") + "-" + gameAttribute1.getFieldName().substring(0, 1).replace("满", "6");
                        }
                    }
                }
                if (StringUtils.isNotEmpty(wuxing)) {
                    params.put("wuxing", wuxing.substring(1));
                }
            }
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF17())) {
                String wuqi = "";
                List<GameAttribute> gameAttributeList = getGameAttributs(goodsInfoAndAttrValueDto.getF17());
                JSONArray jsonArray = JSONArray.parseArray(getWuxingwuqi());
                for (GameAttribute gameAttribute1 : gameAttributeList) {
                    for (Object o : jsonArray) {
                        if (gameAttribute1.getFieldName().contains(JSONObject.parseObject(o.toString()).getString("name"))) {
                            wuqi += "," + JSONObject.parseObject(o.toString()).getString("id") + "-" + gameAttribute1.getFieldName().substring(1, 2).replace("满", "6");
                        }
                    }
                }
                if (StringUtils.isNotEmpty(wuqi)) {
                    params.put("wuxingwuqi", wuqi.substring(1));
                }
            }
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF3())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
                if(gameAttribute1.getFieldName().equals("男主")){
                    params.put("sex", 1);
                }else {
                    params.put("sex", 2);
                }
            }else{
                params.put("sex", 1);
            }
        }


        String pifu = "";
        if (CollectionUtils.isNotEmpty(gameAttributesss)) {
            for (GameAttribute gameAttribute1 : gameAttributesss) {
                String fieldName = gameAttribute1.getFieldName();
                if(fieldName.contains("-")){
                    fieldName = fieldName.split("-")[1];
                }
                pifu += "," + fieldName;
            }
        } else {
            pifu = ",无";
        }
        if (!goodsInfoAndAttrValueDto.getGameName().equals("原神")) {
            if(goodsInfoAndAttrValueDto.getGameName().equals("王者荣耀")&&"zhumengyou".equals(sa.getOther())){
                params.put("heroskin", pifu.substring(1));
            }else {
                params.put("pifu", pifu.substring(1));
            }
        }
//        params.put("pifu", "无");

        GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
        goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
        goodsInfoImg.setType(Constants.STR_1);
        List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
        String images = infoImgs.stream().map(info -> info.getImgUrl()).collect(Collectors.toList()).stream().collect(Collectors.joining(","));
        if (StringUtils.isNotEmpty(images)) {
        } else {
            images = LCConstant.defaultImg;
        }
        params.put("images", images);
        String cover = MapUntils.getCover(params);
        String key = "";
        if (goodsInfoAndAttrValueDto.getGameName().equals("和平精英")) {
            key = "ebb8dd14ff84552eab6c4bbccf5c9d32";
        } else if (goodsInfoAndAttrValueDto.getGameName().equals("王者荣耀")&&!sa.getOther().equals("zhumengyou")) {
            if(sa.getSaleKey().contains("28c8edde3d61a0411511d3b1866f0636")){
                key = "28c8edde3d61a0411511d3b1866f0636";
            }else {
                key = "614f757da7117ef6e631f6780cbcb0ea";
            }
        } else if (goodsInfoAndAttrValueDto.getGameName().equals("原神")) {
            key = "28c8edde3d61a0411511d3b1866f0636";
        } else if (goodsInfoAndAttrValueDto.getGameName().equals("王者国服")||sa.getOther().equals("zhumengyou")) {
            key = "614f757da7sek9f6e631f6780cbcb0ea";
        }
        cover = cover + "key=" + key;
        log.info(cover);
        String sign = DigestUtils.md5Hex(cover).toUpperCase();
        params.put("sign", sign);
        return params;
    }

    private List<GameAttribute> getGameAttributs(String ids) {
        List<GameAttribute> list = new ArrayList<>();
        if (StringUtils.isNotEmpty(ids)) {
            list = gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(ids.split(","),
                    Long.class));
        }
        return list;
    }

    private String reIds(String allIds, String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            if (StringUtils.isNotEmpty(allIds)) {
                allIds = allIds + "," + ids;
            } else {
                allIds = ids;
            }
        }
        return allIds;
    }

    private String regionalCover(SalePartner salePartner, String game, String regional) {
        if(salePartner.getSaleKey().contains("28c8edde3d61a0411511d3b1866f0636")){
            if (game.equals(GameTypeConstant.WZRY)) {
                if (Objects.equals("安卓QQ", regional)) {
                    return "4";
                } else if (Objects.equals("安卓微信", regional)) {
                    return "5";
                } else if (Objects.equals("苹果微信", regional)) {
                    return "7";
                } else if (Objects.equals("苹果QQ", regional)) {
                    return "6";
                } else {
                    return null;
                }
            } else if (game.equals(GameTypeConstant.HPJY)) {
                if (Objects.equals("安卓QQ", regional)) {
                    return "11";
                } else if (Objects.equals("安卓微信", regional)) {
                    return "13";
                } else if (Objects.equals("苹果微信", regional)) {
                    return "12";
                } else if (Objects.equals("苹果QQ", regional)) {
                    return "10";
                } else {
                    return null;
                }
            } else if (game.equals(GameTypeConstant.YS)) {
                if (regional.equals("游戏官方")) {
                    return "4";
                } else {
                    return "10";
                }
            }
        }else {
            if(salePartner.getOther().equals("zhumengyou")){
                if (game.equals(GameTypeConstant.WZRY)) {
                    if (Objects.equals("安卓QQ", regional)) {
                        return "16";
                    } else if (Objects.equals("安卓微信", regional)) {
                        return "17";
                    } else if (Objects.equals("苹果微信", regional)) {
                        return "19";
                    } else if (Objects.equals("苹果QQ", regional)) {
                        return "18";
                    } else {
                        return null;
                    }
                }
            }else {
                if (game.equals(GameTypeConstant.WZRY)) {
                    if (Objects.equals("安卓QQ", regional)) {
                        return "7";
                    } else if (Objects.equals("安卓微信", regional)) {
                        return "9";
                    } else if (Objects.equals("苹果微信", regional)) {
                        return "8";
                    } else if (Objects.equals("苹果QQ", regional)) {
                        return "6";
                    } else {
                        return null;
                    }
                } else if (game.equals(GameTypeConstant.HPJY)) {
                    if (Objects.equals("安卓QQ", regional)) {
                        return "11";
                    } else if (Objects.equals("安卓微信", regional)) {
                        return "13";
                    } else if (Objects.equals("苹果微信", regional)) {
                        return "12";
                    } else if (Objects.equals("苹果QQ", regional)) {
                        return "10";
                    } else {
                        return null;
                    }
                } else if (game.equals(GameTypeConstant.YS)) {
                    if (regional.equals("游戏官方")) {
                        return "4";
                    } else {
                        return "10";
                    }
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {
        Map<String, Object> params = new TreeMap<>();
//        params.put("type", "AddGame");
//        params.put("catid", 11);
//        params.put("title", "测试一下哈哈哈哈");
////        String titleImg = goodsInfoAndAttrValueDto.getTitleImg();
//        params.put("thumb", "http://wimg.shouyou68.com/202303/14/1615222471.jpg");
//        params.put("username", "xiaoyangren");
//        params.put("duanweip","1");
//        params.put("taozhuangp", 20);
//        params.put("dengjip", 30);
//        params.put("ztpricep", 40);
//        params.put("daqup", "苹果微信");
//        params.put("pifu", "SCAR-粉色回忆,SCAR-粉色回忆,SCAR-粉色回忆");
//        params.put("qiangxiep", "0");
//        params.put("game_id", "927");
//        params.put("images", LCConstant.defaultImg);
//        params.put("toukuip", "21");
//        params.put("beibaop","21");
//        params.put("jaingluosanp", "21");
//        params.put("hdengji", "21");
//        params.put("yinji", "21");
//        String cover = MapUntils.getCover(params);
//        cover = cover + "key=ebb8dd14ff84552eab6c4bbccf5c9d32";
//        log.info(cover);
//        String sign = DigestUtils.md5Hex(cover).toUpperCase();
//        params.put("sign", sign);
//        log.info(params);
//        String result = HttpUtils.doPostForm("http://duoduo.sycwy.cn/api/partner/heping.php", params, null);
//        String result  = getWuxingwuqi();

//        log.info(MapUntils.unicodeToString(result));
//        String result = "精2波乱月白经津";
//        log.info(result.substring(1, 2));
        String wuxing = getWuxing();
        System.out.println(wuxing);
    }


    static String getWuxing() {
        Map<String, Object> params = new TreeMap<>();
        String result = HttpUtils.doPostForm("http://le.sycwy.cn/ajax.php?action=fiedles&type=neice", params, null);
        return result;
    }

    static String getSixing() {
        Map<String, Object> params = new TreeMap<>();
        String result = HttpUtils.doPostForm("http://ys.sycwy.cn/ajax.php?action=fiedles&type=sixing", params, null);
        ;
        return result;
    }

    static String getWuxingwuqi() {
        Map<String, Object> params = new TreeMap<>();
        String result = HttpUtils.doPostForm("http://ys.sycwy.cn/ajax.php?action=fiedles&type=wuxingwuqi", params, null);
        ;
        return result;
    }
}
